﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _92流程控制_循环  //for while  do-while
{
    internal class Program
    {
        //简单使用,固定次数的重复
        private static void Main1(string[] args)
        {
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(i + "新年快乐!");
            }
        }
        //求[0-100]累加和
        private static void Main2(string[] args)
        {
            int sum = 0;//求和必先定义sum变量用来装总数
            for (int i = 0; i <= 100; i++)
            {
                sum += i;
            }
            Console.WriteLine(sum);
        }
        //输出[88-77]之间的偶数数不包括88,77
        private static void Main4(string[] args)
        {
            for (int i = 87; i > 77; i--)
            {
                Console.WriteLine(i);
            }
        }
        // 100块 做生意 每天赚2% ,第一天的本金加利润投入第二天再生产 问365天后你有多少钱

        private static void Main5(string[] args)
        {
            decimal money = 100.0m;
            for (int i = 1; i <= 365; i++)
            {
                money *= 1.02m;
                //money = money + money * 0.02m;
            }
            Console.WriteLine(money);
        }

        //循环嵌套
        private static void Main6(string[] args)
        {
            for (int i = 0; i < 5; i++)//外层循环每做1次内层循环都会做完
            {
                Console.WriteLine("外层循环第{0}", i);
                for (int j = 0; j < 5; j++)
                {
                    Console.WriteLine("{0}:{1}", i, j);
                }
            }
        }

        //while  先判断再做,条件不成立了就不做了
        private static void Main7(string[] args)
        {
            int sum = 0;
            int i = 0;
            while (i <= 100)
            {
                sum += i;
                // Console.WriteLine(i);
                i++;
            }
            Console.WriteLine(sum);
        }
        // 100块 做生意 每天赚10% ,第一天的本金加利润投入第二天再生产 问需要多少天赚够1个亿
        private static void Main8(string[] args)
        {
            int day = 0;
            double money = 100;
            while (money < 100000000)
            {
                day++;
                money *= 1.1;
            }
            Console.WriteLine(day);
        }

        //do while 先做一次再判断,条件不成立就不做了
        private static void Main9(string[] args)
        {
            int i = 0;
            do
            {
                Console.WriteLine(i);
                i++;
            } while (i <= 100);
        }

        private static void Main(string[] args)
        {
            int n = 0;
            double money = 100;
            do
            {
                n++;
                money *= 1.1;
            } while (money < 100000000);
            Console.WriteLine(n);
        }
    }
}